import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import store from './store'

Vue.config.productionTip = false

Vue.use(ElementUI);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');


// 在页面卸载时将vuex里的信息保存到sessionStorage里
window.addEventListener("beforeunload", () => {
  sessionStorage.setItem("store", JSON.stringify(store.state));
});

// 页面加载时，将sessionStorage里面的数据加载进vuex中（利用vuex提供的replaceState函数）
const storeItem = sessionStorage.getItem("store");
if (storeItem) {
  store.replaceState(Object.assign({}, store.state, JSON.parse(storeItem)));
}